<template>
    <h1>用户登录</h1>
<table border="1">
    <tr>
        <td>用户名</td>
        <td>
            <input type="text" v-model="info.Mname" />
        </td>
    </tr>
    <tr>
        <td>密码</td>
        <td>
            <input type="password" v-model="info.Mpwd" />
        </td>
    </tr>
    <tr>
        <td></td>
        <td>
            <input type="button" value="登录" @click="login"/>
        </td>
    </tr>
</table>
</template>


<script setup lang="ts">
import { ref } from 'vue';
import axios from 'axios';

const info=ref({
    Mname:'',
    Mpwd:''
})

const login=()=>{
    if(!info.value.Mname){
        alert("用户名不能为空");
        return;
    }
    if(!info.value.Mpwd){
        alert("密码不能为空");
        return;
    }
    if(info.value.Mpwd.length<6){
        alert("密码长度不得少于6位");
        return;
    }
    var reg=/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,10}$/;
    if(!reg.test(info.value.Mpwd)){
        alert("密码必须包含数字和字母且长度在6-10位之间");
        return;
    }
    let obj={
        mname:info.value.Mname,
        mpwd:info.value.Mpwd
    }
    axios.get("https://localhost:7193/api/Meber/MeberLogin",{
        params:obj
    })
    .then(res=>{
        console.log(res);
        if(res.data==-1){
            alert("用户名不存在");
        }
        else if(res.data==-2){
            alert("密码错误");
        }
        else if(res.data>0){
            alert("登录成功");
        }
        else{
            alert("登录失败"); 
        }
    })
}

</script>